const bar = 'hello world';

const myIndexOf = (foo, bar) => {
  if (bar === '') return 0;
  const fooLength = foo.length;
  const barLength = bar.length;
  if (fooLength < barLength) return -1;
  for (let i = 0; i <= fooLength - barLength; i++) {
    let match = true;
    for (let j = 0; j < barLength; j++) {
      if (foo[i + j] !== bar[j]) {
        match = false;
        break;
      }
    }
    if (match) return i;
  }
  return -1;
};

console.log(myIndexOf(bar, 'world'));
console.log(myIndexOf(bar, '1'));
console.log(myIndexOf(bar, ''));
